package com.ideaaedi.zoo.example.springboot.mq.rocketmq;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;

import java.util.function.Consumer;

/**
 * 消费者示例
 */
@Configuration
public class DemoConsumer {
    
    @Bean(value = "consumerA")
    public Consumer<Message<String>> provideConsumerA () {
        return new Consumer<Message<String>>() {
            @Override
            public void accept(Message<String> message) {
                String msg = message.getPayload();
                System.out.println("\nconsumeA接收到消息：\nmsg=" + msg + "\nheaders=" + message.getHeaders());
            }
        };
    }
    
    @Bean(value = "consumerB")
    public Consumer<Message<String>> provideConsumerB () {
        return new Consumer<Message<String>>() {
            @Override
            public void accept(Message<String> message) {
                String msg = message.getPayload();
                System.out.println("\nconsumeB接收到消息：\nmsg=" + msg + "\nheaders=" + message.getHeaders());
            }
        };
    }
    
    @Bean(value = "consumerC")
    public Consumer<Message<String>> provideConsumerC () {
        return new Consumer<Message<String>>() {
            @Override
            public void accept(Message<String> message) {
                String msg = message.getPayload();
                System.out.println("\nconsumeC接收到消息：\nmsg=" + msg + "\nheaders=" + message.getHeaders());
            }
        };
    }
}